// pages/mine/order/order.js
import request from '../../utils/request'
Page({
    click(e){
        this.setData({Index:e.currentTarget.dataset.index})
        let a = this.data.navList.filter(item=>{
            if(this.data.Index === 1){
                return item.state === '1'
            }else if(this.data.Index === 2){
                return item.state === '2'
            }else if(this.data.Index === 3){
                return item.state === '3'
            }
        })
        this.setData({sxList:a})
        console.log(this.data.sxList);
    },
    search(){
        wx.navigateTo({
          url: '../order/search/search',
        })
    },
    Num(options){
        console.log();
        this.setData({sxList:JSON.parse(decodeURIComponent(options.sxList))})
        let num = Number(options.index)
        this.setData({Index:num})  
    },
    Tiao(){
        wx.switchTab({
          url: '../home/home',
        })
    },
    Okgoods(e){
        console.log(e.currentTarget.dataset.id);
        wx.showLoading({
          title: '确认提货中',
        })
        setTimeout(function(){
            wx.hideLoading()
            wx.showToast({
                title: '提货成功',
            })
        },1000)
        request("/Okgoods",{id:e.currentTarget.dataset.id},{'content-type':'application/json'},"GET")
    },
    Okmoney(e){
        wx.showLoading({
            title: '支付中',
          })
          setTimeout(function(){
              wx.hideLoading()
              wx.showToast({
                  title: '支付成功',
              })
          },1000)
        request("/Okmoney",{id:e.currentTarget.dataset.id},{'content-type':'application/json'},"GET")
    },
    del(e){
        console.log(e.currentTarget.dataset.id);
        wx.showLoading({
            title: '删除中',
          })
          setTimeout(function(){
              wx.hideLoading()
              wx.showToast({
                  title: '删除成功',
              })
          },1000)
        request("/Delgoods",{id:e.currentTarget.dataset.id},{'content-type':'application/json'},"GET")
    },
    twoShop(e){
        const param = encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item));
        wx.navigateTo({
          url: `../classify/shopDetail/shopDetail?obj=${param}`,
        })
    },
    /**
     * 页面的初始数据
     */
    data: {
        title:['全部','待支付','待提货','已提货'],
        Index:0,
        navList:[],
        sxList:[]
    },
    async GetOrder(){
        let payload = await request('/order',{},'GET').then(res=>{
            return res
        })
        this.setData({navList:payload})
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.Num(options)
        this.GetOrder()
        wx.setNavigationBarTitle({
          title: '订单管理',
        })
        wx.setNavigationBarColor({
            backgroundColor: '#fffff',
            frontColor: '#000000',
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})